class OffPromotionSubjectProduct
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Attributes::Dynamic

  field :product_id, type: String

  field :is_promotion, type: Integer, default: 1#是否参加活动0否1是

  field :product_active_price, type: Float#活动价格

  field :sequencing, type: Integer, default: 0#排序字段
  field :promotion_stock, type: Integer, default: 1 #促销库存
  field :promotion_sale, type: Integer, default: 0 #促销销售
  field :start_time, type: DateTime #活动开始时间
  field :end_time, type: DateTime#活动截止时间
  field :userinfo_id, type: String #小 B id
  field :status, type: Integer, default: 0 #活动商品状态，-1：已结束 0为待启用 1: 已开始

  belongs_to :product_group

  attr_readonly *fields.keys

  def is_starting

    return self.start_time.to_i < Time.now.to_i && self.end_time.to_i > Time.now.to_i && self.promotion_sale < self.promotion_stock && self.status==1
  end



  def is_promotion_str
    is_promotion==0 ? "不参加" : "参加"

  end

end
